from flask import request, Blueprint, render_template, redirect, url_for, jsonify
from data import PostgreSQLWrapper
add_ip_bp = Blueprint('add_ip', __name__)

@add_ip_bp.route('/add_ip', methods=['GET', 'POST'])
def add_ip():
    print("111",request.method)
    if request.method == 'POST':
        line = request.form['line']
        address = request.form['address']
        software = request.form['software']
        product_type = request.form['product_type']
        print(line,address,software,product_type)   
        db = PostgreSQLWrapper()
        if db.add_ip_config(line, address, software, product_type):
            return redirect(url_for('page1', error='添加成功'))
        else:
            return render_template('add_ip.html',error='添加失败')  
    return render_template('add_ip.html')